try:
    # 尝试导入reportlab库，如果不存在则安装
    from reportlab.lib.pagesizes import letter
    from reportlab.pdfgen import canvas
    from reportlab.lib.utils import ImageReader
    import os
    
    def create_test_pdf(output_path='test_document.pdf', num_pages=3):
        """
        创建一个测试用的多页PDF文件
        
        参数:
        output_path (str): 输出PDF文件路径
        num_pages (int): PDF页数
        """
        # 创建canvas对象
        c = canvas.Canvas(output_path, pagesize=letter)
        width, height = letter
        
        print(f"创建测试PDF文件: {output_path} ({num_pages}页)")
        
        for page_num in range(1, num_pages + 1):
            # 设置标题
            c.setFont("Helvetica-Bold", 16)
            c.drawString(72, height - 72, f"测试文档 - 第 {page_num} 页")
            
            # 添加一些文本
            c.setFont("Helvetica", 12)
            text_lines = [
                "这是一个测试PDF文档，用于验证PDF转JPG功能。",
                "",
                f"当前页码: {page_num}",
                f"总页数: {num_pages}",
                "",
                "生成时间: 当前时间",
                "",
                "测试内容行1",
                "测试内容行2",
                "测试内容行3"
            ]
            
            y_position = height - 120
            for line in text_lines:
                c.drawString(72, y_position, line)
                y_position -= 20
            
            # 添加一些图形元素
            # 绘制矩形
            c.rect(72, y_position - 50, width - 144, 40)
            c.drawString(80, y_position - 30, "这是一个矩形区域")
            
            # 绘制圆形
            c.circle(width - 150, y_position - 30, 20)
            c.drawString(width - 180, y_position - 60, "圆形")
            
            # 绘制线条
            c.line(72, y_position - 100, width - 72, y_position - 100)
            
            # 完成当前页面
            c.showPage()
        
        # 保存PDF文件
        c.save()
        print(f"PDF文件已成功创建: {output_path}")
        print(f"文件大小: {os.path.getsize(output_path) / 1024:.2f} KB")
        
    if __name__ == "__main__":
        create_test_pdf()
except ImportError:
    # 如果reportlab库不存在，安装它
    print("reportlab库未找到，正在安装...")
    import subprocess
    import sys
    subprocess.check_call([sys.executable, "-m", "pip", "install", "reportlab"])
    print("安装完成，请重新运行此脚本生成测试PDF文件。")